<!-- 管理员用户组新增和编辑页面 -->
<extend name="common/base" />
<block name="body">
	<!-- 访问授权 -->
	<form action="{:url('Auth/writeGroup')}" enctype="application/x-www-form-urlencoded" method="POST" class="form-horizontal auth-form">
		<volist name="node_list" id="node" >
			<dl class="checkmod">
				<dt>
					<label class="tit"><input class="auth_rules rules_all" type="checkbox" data-toggle="icheck" name="rules[]" value="<?php echo $main_rules[$node['url']] ?>">{$node.title}管理</label>
				</dt>
				<dd>
					<present name="node['child']">
					<volist name="node['child']" id="child" >
                        <div class="rule_check">
                            <div>
                                <label class="tit" <notempty name="child['tip']">title='{$child.tip}'</notempty>>
                                    <input class="auth_rules rules_row" type="checkbox" data-toggle="icheck" name="rules[]" value="<?php echo $auth_rules[$child['url']] ?>"/>{$child.title}
                                </label>
                            </div>
                            <notempty name="child['operator']">
                                <span class="divsion">&nbsp;</span>
                                <span class="child_row">
                                    <volist name="child['operator']" id="op">
                                        <label class="tit" <notempty name="op['tip']">title='{$op.tip}'</notempty>>
                                           <input class="auth_rules" type="checkbox" data-toggle="icheck" name="rules[]" value="<?php echo $auth_rules[$op['url']] ?>"/>{$op.title}
                                        </label>
                                    </volist>
                                </span>
                            </notempty>
				        </div>
					</volist>
					</present>
				</dd>
			</dl>
		</volist>

		<input type="hidden" name="id" value="{$this_group.id}" />
        <button type="submit" class="btn btn-success ajax-post" target-form="auth-form">确 定</button>
        <button class="btn btn-danger" onclick="javascript:history.back(-1);return false;">返 回</button>
	</form>

</block>
<block name="script">
<script type="text/javascript" src="__STATIC__/jquery/qtip/jquery.qtip.min.js"></script>
<link rel="stylesheet" type="text/css" href="__STATIC__/jquery/qtip/jquery.qtip.min.css" media="all">
<script type="text/javascript" charset="utf-8">
    +function($){
        var rules = [{$this_group.rules}];
        $('.auth_rules').each(function(){
            if( $.inArray( parseInt(this.value,10),rules )>-1 ){
                $(this).attr('checked',true).iCheck('update');
            }
            if(this.value==''){
                $(this).closest('span').remove();
            }
        });

        //全选节点
        $('.rules_all').on('change',function(){
            $(this).closest('dl').find('dd').find('input').prop('checked',this.checked).iCheck('update');
        });
        $('.rules_row').on('change',function(){
            $(this).closest('.rule_check').find('.child_row').find('input').prop('checked',this.checked).iCheck('update');
        });

        $('.checkbox').each(function(){
            $(this).qtip({
                content: {
                    text: $(this).attr('title'),
                    title: $(this).text()
                },
                position: {
                    my: 'bottom center',
                    at: 'top center',
                    target: $(this)
                },
                style: {
                    classes: 'qtip-dark',
                    tip: {
                        corner: true,
                        mimic: false,
                        width: 10,
                        height: 10
                    }
                }
            });
        });

        $('select[name=group]').change(function(){
			location.href = this.value;
        });
    }(jQuery);
</script>
</block>
